home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
svgadc30.zip
/
svgamap.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-03-03
|
19KB
|
733 lines
program SVGA_Bitmap_Maker;
{ Use mouse to choose color and draw image }
{ The followig keys can be used as follows }
{ 'Q' - No nonsense quit }
{ 'S' - Save image to disk. Will be prompted }
{ for a filename. }
{ 'L' - Load image from disk. Will be prompted }
{ for a filename. }
{ 'P' - Change width of each pixel element of }
{ drawing. Range 1..9 }
{ 'N' - New image. Clears present image from }
{ memory. Prompts for 'Y' or 'N' }
{ 'C' - Change image size. Will delete present }
{ image from memory and start with new }
{ sized image. Image dimensions are }
{ measured in pixels. If not enough }
{ memory on heap image size will not }
{ be allowed. }
{ 'M' - Move image around screen to get at }
{ hard to reach places. Press escape }
{ when done. }
{ 'X' - Load a palette from disk. Prompts for }
{ filename. }
{ 'E' - Left over from development of this }
{ program. Simply puts image to screen }
{ whereever mouse pointer is. }
{ If you want to exit from 'load' , 'save' etc }
{ without the program doing anything simply }
{ press enter with no input i.e. null string '' }
uses SVGA, Crt;
type YPtr = ^YType;
YType = record
Col1, Col2, Col3, Col4 : byte; { Due to TP's memory }
NextY : YPtr; { memory management }
end; { pointers are multiples}
XPtr = ^XType; { of 8 bytes }
XType = record
NextX : XPtr;
Y : YPtr;
end;
var GM : GraphicMouse;
Vx, Vy, PixelWidth, XPos, YPos, Btn, TX, TY, Bx, By : integer;
ActiveColor, MaxHeight, MaxWidth : byte;
XCoord, YCoord, resp, ImageName, PaletteName : string;
Quit : boolean;
Ch : char;
Image : XPtr;
HeapMem : longint;
procedure PutImage( x, y : integer; Img : XPtr );
var xx, yy : integer;
Offset, bank : longint;
procedure TraverseYPtr( Yp : YPtr );
begin
if Yp <> nil then
begin
Bank := Offset shr 16;
if Bank <> PresentSeg then LoadWriteBank( Bank );
MEM[$A000:Offset] := Yp^.Col1;
inc( Offset, Bytes_per_line );
Bank := Offset shr 16;
if Bank <> PresentSeg then LoadWriteBank( Bank );
MEM[$A000:Offset] := Yp^.Col2;
inc( Offset, Bytes_per_line );
Bank := Offset shr 16;
if Bank <> PresentSeg then LoadWriteBank( Bank );
MEM[$A000:Offset] := Yp^.Col3;
inc( Offset, Bytes_per_line );
Bank := Offset shr 16;
if Bank <> PresentSeg then LoadWriteBank( Bank );
MEM[$A000:Offset] := Yp^.Col4;
inc( Offset, Bytes_per_line );
inc( yy, 4 );
TraverseYPtr( Yp^.NextY );
end;
end;
procedure TraverseXPtr( Xp : XPtr );
begin
if Xp <> nil then
begin
Offset := (longint(yy)*Bytes_per_line)+xx;
TraverseYPtr( Xp^.Y );
yy := y;
inc( xx );
TraverseXPtr( Xp^.NextX );
end;
end;
begin
xx := x;
yy := y;
TraverseXPtr( Img );
end;
procedure SaveImage( Img : XPtr );
var f : file of byte;
procedure TraverseYPtr( Yp : YPtr );
begin
if Yp <> nil then
begin
write( f, Yp^.Col1 );
write( f, Yp^.Col2 );
write( f, Yp^.Col3 );
write( f, Yp^.Col4 );
TraverseYPtr( Yp^.NextY );
end;
end;
procedure TraverseXPtr( Xp : XPtr );
begin
if Xp <> nil then
begin
TraverseYPtr( Xp^.Y );
TraverseXPtr( Xp^.NextX );
end;
end;
begin
assign( f, imagename );
rewrite( f );
write( f, MaxWidth, MaxHeight );
TraverseXPtr( Img );
close( f );
end;
procedure DrawImage;
var xx, yy, vvx, vvy : integer;
procedure TraverseYPtr( Yp : YPtr );
procedure PlotCol( c : byte; x: integer; var y : integer );
begin
if yy < By then
begin
RectFill( x*PixelWidth, y*PixelWidth, x*PixelWidth+PixelWidth-1,
y*PixelWidth+PixelWidth-1, c );
if (500+x < GetMaxX) and (300+y < GetmaxY) then
Plot( 500+x, 300+y, c );
inc( y );
end;
end;
begin
if vvy >= Vy then
begin
if (Yp <> nil) then
begin
PlotCol( Yp^.Col1, xx, yy );
PlotCol( Yp^.Col2, xx, yy );
PlotCol( Yp^.Col3, xx, yy );
PlotCol( Yp^.Col4, xx, yy );
TraverseYPtr( Yp^.NextY );
end;
end
else
begin
inc( vvy, 4 );
if Yp <> nil then TraverseYPtr( Yp^.NextY );
end
end;
procedure TraverseXPtr( Xp : XPtr );
begin
if vvx >= Vx then
begin
if (Xp <> nil) and (xx < Bx) then
begin
TraverseYPtr( Xp^.Y );
yy := 0; vvy := 0;
inc( xx );
TraverseXPtr( Xp^.NextX );
end;
end
else
begin
inc( vvx );
if Xp <> nil then TraverseXPtr( Xp^.NextX );
end;
end;
begin
GM.Show( False );
ClearPort( 0, 0, GetMaxX-140, GetMaxY );
RectFill( 500,300,GetMaxX, GetMaxY, 0 );
xx := 0; vvx := 0;
yy := 0; vvy := 0;
TraverseXPtr( Image );
GM.Show( True );
end;
procedure LoadImage( var ImagePtr : XPtr );
var f : file of byte;
Col1, Col2, Col3, Col4, th : byte;
procedure ReadY( var Yp : YPtr );
var TmpY : YPtr;
begin
new( TmpY );
read( f, Col1, Col2, Col3, Col4 );
TmpY^.Col1 := Col1;
TmpY^.Col2 := Col2;
TmpY^.Col3 := Col3;
TmpY^.Col4 := Col4;
inc( th, 4 );
if th < MaxHeight then
ReadY( TmpY^.NextY )
else
TmpY^.NextY := nil;
Yp := TmpY;
end;
procedure ReadX( var Xp : XPtr );
var TmpX : XPtr;
begin
if not eof( f ) then
begin
new( TmpX );
ReadY( TmpX^.Y );
th := 1;
ReadX( TmpX^.NextX );
Xp := TmpX;
end
else
Xp := nil;
end;
begin
assign( f, ImageName );
reset( f );
read( f, MaxWidth, MaxHeight );
th := 1;
ReadX( ImagePtr );
close( f );
end;
procedure SetImageCol( x, y, NewCol : byte; var Img : XPtr );
var xx, yy : byte;
procedure TraverseYPtr( var Yp : YPtr );
function ic( var t : byte ): byte;
begin
inc( t );
ic := t;
end;
begin
if Yp <> nil then
begin
if yy = y then Yp^.Col1 := NewCol
else if ic(yy) = y then Yp^.Col2 := NewCol
else if ic(yy) = y then Yp^.Col3 := NewCol
else if ic(yy) = y then Yp^.Col4 := NewCol
else
begin
inc( yy );
TraverseYPtr( Yp^.NextY );
end;
end;
end;
procedure TraverseXPtr( var Xp : XPtr );
begin
if Xp <> nil then
begin
if xx = x then
TraverseYPtr( Xp^.Y )
else
begin
inc( xx );
TraverseXPtr( Xp^.NextX );
end
end;
end;
begin
xx := 0;
yy := 0;
TraverseXPtr( Img );
end;
procedure ClearMemory( var Img : XPtr );
procedure TraverseYPtr( Yp : YPtr );
begin
if Yp <> nil then
begin
Yp^.Col1 := 0;